﻿using System.Collections;
using UnityEngine;

public enum MonsterEnum
{
    Normal,
    Remote
}
public class EnemyRetard : MonoBehaviour
{
    public MonsterEnum monsterState;
    private Coroutine coroutine;
    private float moveSpeed;
    public void StartRetard(float data, float time)
    {
        NormalMonster_AI normalMonster = GetComponent<NormalMonster_AI>();
        if (coroutine != null)
        {
            if (monsterState == MonsterEnum.Normal)
            {
                GetComponent<NormalMonster_AI>().moveSpeed = moveSpeed;
            }
            else if (monsterState == MonsterEnum.Remote)
            {
                GetComponent<RemoteMonster_AI>().moveSpeed = moveSpeed;
            }
        }
        coroutine = StartCoroutine(Retard(data, time));
    }
   // 减速携程
    private IEnumerator Retard(float data, float time)
    {
        if (monsterState == MonsterEnum.Normal)
        {
            moveSpeed = GetComponent<NormalMonster_AI>().moveSpeed;
            GetComponent<NormalMonster_AI>().moveSpeed -= moveSpeed * data;

            yield return new WaitForSeconds(time);
            GetComponent<NormalMonster_AI>().moveSpeed = moveSpeed;
        }
        else if (monsterState == MonsterEnum.Remote)
        {
            moveSpeed = GetComponent<RemoteMonster_AI>().moveSpeed;
            GetComponent<NormalMonster_AI>().moveSpeed -= moveSpeed * data;
            yield return new WaitForSeconds(time);
            GetComponent<RemoteMonster_AI>().moveSpeed = moveSpeed;
        }
    }

}
